#!/bin/bash


main(){

chmod 0755 mtail
./mtail --version
mkdir /etc/mtail
touch /etc/mtail/line_count.mtail
counter line_count

/$/  {
       line_count++
     }
~

./mtail --progs /etc/mtail/ --logs '/opt/logs/error' --port 9111

}

config(){
# check latest version from github
wget https://github.com/google/mtail/releases/download/v3.0.0-rc47/mtail_3.0.0-rc47_Linux_x86_64.tar.gz

tar xf mtail_3.0.0-rc47_Linux_x86_64.tar.gz
# can choose to cp mtail to /usr/local/bin
# cp mtail /usr/local/bin

# 查看mtail版本
./mtail --version
mtail version 3.0.0-rc47 git revision 5e0099f843e4e4f2b7189c21019de18eb49181bf go version go1.16.5 go arch amd64 go os linux

# mtail后盾启动
nohup mtail -port 3903 -logtostderr -progs test.mtail -logs test.log &

# 默认端口是3903
nohup ./mtail -progs test.mtail -logs test.log &

# 查看是否启动胜利
ps -ef | grep mtail
}

launching_under_docker(){

# The -P flag ensures mtail-myapp's port 3903 is exposed for collection, refer to docker ps to find out where it's mapped to on the host.
mkdir /etc/mtail
sudo docker stop myapp-mtail;sudo docker rm myapp-mtail;
sudo docker run -d \
   -p 3903:3903   \
   --name myapp-mtail \
   -v /var/log/zcm/nms-metrics.log:/var/log/zcm/nms-metrics.log \
   -v /etc/mtail:/etc/mtail \
   dylanmei/mtail:latest --logs /var/log/zcm/nms-metrics.log --progs /etc/mtail

sudo docker stop myapp-mtail;sudo docker rm myapp-mtail; \
sudo docker run -itd \
   -p 3903:3903   \
   --name myapp-mtail \
   -v /var/log/zcm/nms-metrics.log:/var/log/zcm/nms-metrics.log \
   -v /etc/mtail:/etc/mtail \
   dylanmei/mtail:latest --logs /var/log/zcm/nms-metrics.log --progs /etc/mtail

}


main
